﻿using Basic.ScheduledTask.Abstract;
using System.Linq.Expressions;

namespace Basic.ScheduledTask
{
    public class JobStaticManager
    {
        private static IJobManager _manager;

        public JobStaticManager(IJobManager manager)
        {
            _manager = manager;
        }

        #region 同步

        public static void AddOnceJob(Expression<Action> expression) => _manager.AddOnceJob(expression);

        public static void AddOnceJob(Expression<Action> expression, DateTimeOffset time) => _manager.AddOnceJob(expression, time);

        public static void DelayJob(Expression<Action> expression, TimeSpan delayTime) => _manager.DelayJob(expression, delayTime);

        public static string AddRecurringJob(string jobId, Expression<Action> expression, string cron) => _manager.AddRecurringJob(jobId, expression, cron);

        public static string AddRecurringJob<T>(string jobId, Expression<Action<T>> expression, string cron) where T : class
        {
            return _manager.AddRecurringJob(jobId, expression, cron);
        }

        #endregion

        #region 异步

        public static void AddOnceJob(Expression<Func<Task>> expression) => _manager.AddOnceJob(expression);

        public static void AddOnceJob(Expression<Func<Task>> expression, DateTimeOffset time) => _manager.AddOnceJob(expression, time);

        public static string AddRecurringJob(Expression<Func<Task>> expression, string cron) => AddRecurringJob(Guid.NewGuid().ToString(), expression, cron);

        public static string AddRecurringJob(string jobId, Expression<Func<Task>> expression, string cron) => _manager.AddRecurringJob(jobId, expression, cron);

        public static string AddRecurringJob<T>(string jobId, Func<T, Task> expression, string cron) where T : class
        {
            return _manager.AddRecurringJob(jobId, expression, cron); ;
        }

        public static void DelayJob(Expression<Func<Task>> expression, TimeSpan delayTime) => _manager.DelayJob(expression, delayTime);

        #endregion

        public static void RemoveJob(string jobId) => _manager.RemoveJob(jobId);

    }
}